class SolutionZsh {
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length == 0) return 0;
        int currentMin = prices[0];
        int currentMax = 0;
        int maxValue = 0;
        for(int i = 1; i < prices.length; i++) {
            if (prices[i] > currentMin && prices[i] > currentMax) {
                currentMax = prices[i];
                if (currentMax - currentMin > maxValue)
                    maxValue = currentMax - currentMin;
            } else if (prices[i] < currentMin) {
                currentMin = prices[i];
                currentMax = 0;
            }
        }
        return maxValue;
    }
}